package com.trsvax.gwthello.components;

import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

import com.trsvax.gwthello.client.GWTHello;
import com.trsvax.gwthello.client.GreetingService;
import com.trsvax.gwthello.client.widget.HelloWidget;

@IncludeJavaScriptLibrary(value = { "context:/gwthello/gwthello.nocache.js" })
public class HelloComponent extends GWTComponent<GWTHello, GreetingService> implements GreetingService {

	@Parameter
	@Property
	private String name;

	@Parameter
	private String value;

	@Persist
	private String last;

	public String getNameArg() {
		return HelloWidget.NAME;
	}

	public Class<GWTHello> getGWTModuleClass() {
		return GWTHello.class;
	}

	public String greetServer(String newname) {
		String greet = "last was: " + last + getContainer().greetServer(newname);
		last = name;
		value = newname;
		return greet;
	}

}
